//
//  CYImageSubView.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/2/1.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "CYImageSubView.h"

@implementation CYImageSubView
{
    UIImageView *_imagev;
    UIButton *_delete;
    NSString *_image_id;
}

-(void)initWidthImage:(UIImage *)image
{
    self.frame = CGRectMake(0, 0, CY_IMAGE_HEIGHT, CY_IMAGE_HEIGHT);
    _imagev = [[UIImageView alloc] init];
    _imagev.image = image;
    _imagev.frame = self.bounds;
    [self addSubview:_imagev];
    _image_id = @"0";
}

-(void)initWidthUrl:(NSDictionary *)model
{
    self.frame = CGRectMake(0, 0, CY_IMAGE_HEIGHT, CY_IMAGE_HEIGHT);
    _imagev = [[UIImageView alloc] init];
    [_imagev sd_setImageWithURL:[cyurl safeUrl:[model valueForKey:@"img"]] placeholderImage:[[CYCommon sharedCYCommon] getEpmayImage]];
    _imagev.frame = self.bounds;
    [self addSubview:_imagev];
    _image_id = [NSString stringWithFormat:@"%@",[model valueForKey:@"id"]];
    
    _auditLable = [[UILabel alloc] init];
    _auditLable.text = ASLocalizedString(@"审核中");
    _auditLable.font = DEFAULT_FONT(16);
    _auditLable.textColor = KRedColor;
    [self addSubview:_auditLable];
    _auditLable.frame = CGRectMake(0, 0, 40, 30);
    [_auditLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_imagev);
    }];

}

-(void)setType:(NSString *)type
{
    _type = type;
    _delete = [[UIButton alloc] initWithFrame:CGRectMake(self.width - 25, 5, 20, 20)];
    [_delete addTarget:self action:@selector(handleDeleteEvent:) forControlEvents:UIControlEventTouchUpInside];
    [_delete setImage:IMAGE_NAMED(@"home_delete") forState:UIControlStateNormal];
    _imagev.userInteractionEnabled = YES;
    if([type isEqualToString:@"1"])
    {
        [_imagev addSubview:_delete];
    }
    else if([type isEqualToString:@"2"])
    {
        [_imagev addSubview:_delete];
    }
    else if([type isEqualToString:@"3"])
    {
        
    }
}

-(void)layoutSubview{
    
    [super layoutSubviews];
    
}
-(void)handleDeleteEvent:(UIButton *)theButton
{
    if(self.deleClickBlock)
    {
        self.deleClickBlock(_type, _image_id,_index);
    }
    
}

@end
